﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.LockService;
using A2DFramework.InstanceService;
using A2DFramework;
using A2DFramework.LockService.Configuration;
using System.Threading;

namespace LockTestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            A2DFramework.Starter.Init();
            A2DFramework.LockService.Starter.Init();

            //ILock lockSrv=ObjectFactory.Resolve<ILock>();
            //using (lockSrv.AcquireLock("l"))
            //{ 
            //}

            //A2DLock lockObj = lockSrv.AcquireLock("l");
            //lockObj.Dispose();


            //lockObj = lockSrv.AcquireLock("l");
            //lockSrv.ReleaseLock(lockObj);


            ThreadPool.QueueUserWorkItem(new WaitCallback(Do), 1);
            ThreadPool.QueueUserWorkItem(new WaitCallback(Do), 2);

            Console.ReadKey();

        }

        static void Do(object state)
        { 
            int number=(int)state;

            ILock lockSrv = ObjectFactory.Resolve<ILock>();

            while(true)
            {
                A2DLock lockObj = lockSrv.AcquireLock("l");
                //lockObj.Dispose();


                //using (lockSrv.AcquireLock("l"))
                //{
                    Console.WriteLine("Message from " + number);
                //}
            }
        }
    }
}
